
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<base href="<%=basePath%>">
<title>总部</title>
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/css/bootstrap.min.css">
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/css/main.css">
<script src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/js/main.js"></script>
<script src="${pageContext.request.contextPath}/js/MD5.js"></script>
<script src="${pageContext.request.contextPath}/js/city2.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/citySelect2.js"></script>

</head>
<body>
	<%@ include file="header.jsp"%>
	<%@ include file="left.jsp"%>
	<style>
.main_div {
	min-width: 1000px;
	min-height: 60px
}

.force-overflow1-1 {
	border: none
}

.buttonPic>span {
	color: #FFFFFF;
	font-size: 36px
}

.countyVipCount {
	font-size: 18px;
	line-height: 50px
}

.countyVipCount span {
	color: red
}

.pageChange {
	float: right;
	color: #337ab7;
}

.pageChange>span {
	cursor: pointer
}

.pageChange>span:hover {
	color: blue
}

.anotherDetaile {
	width: 1000px;
	height: 160px;
	margin: 0 auto
}

.anotherDetaileButton {
	width: 20%;
	height: 100%;
	float: left
}
</style>
	<div id="index"
		style="position: absolute;left: 180px;top: 80px;bottom: 0;right: 0;">
		<section id="main2" style="display:none">
			<div class="scrollbar1-1" id="style1-1">
				<div class="main_div">
					<div class="main_title">
						<span>直营商家管理</span>
					</div>
					<form id="uploadForm" class="form-horizontal"
						style="margin-top: 30px" enctype="multipart/form-data">
						<div class="form-group">
							<label class="col-xs-4 control-label">商家名称</label>
							<div class="col-xs-4">
								<input type="text" class="form-control" 
									name="directName" placeholder="商家名称">
							</div>
						</div>
						<div class="form-group">
							<label class="col-xs-4 control-label">法人</label>
							<div class="col-xs-4">
								<input type="text" class="form-control" id="superHost"
									name="userName" placeholder="法人">
							</div>
						</div>
						<div class="form-group">
							<label class="col-xs-4 control-label">法人身份证号</label>
							<div class="col-xs-4">
								<input type="text" class="form-control" id="userCard"
									name="userCard" placeholder="身份证号">
							</div>
						</div>
						<div class="form-group">
							<label class="col-xs-4 control-label">联系电话</label>
							<div class="col-xs-4">
								<input type="text" class="form-control" id="phone" name="phone"
									placeholder="联系电话">
							</div>
						</div>
						<div class="form-group">
							<label class="col-xs-4 control-label">账号</label>
							<div class="col-xs-4">
								<input type="text" class="form-control" id="account"
									name="account" placeholder="超市账号">
							</div>
						</div>
						<div class="form-group">
							<label class="col-xs-4 control-label">登录密码</label>
							<div class="col-xs-4">
								<input type="text" class="form-control" id="setPassword"
									placeholder="登录密码">
							</div>
						</div>
						<div class="form-group">
							<label class="col-xs-4 control-label">确认密码</label>
							<div class="col-xs-4">
								<input type="text" class="form-control" id="surePassword"
									placeholder="请再次确认密码"> <input id="passwordOn"
									style="display:none" name="passWord" />
							</div>
						</div>
						<div class="form-group">
							<label class="col-xs-4 control-label">地址</label>
							<div class="col-xs-4">
								<input type="text" class="form-control" id="superAddress"
									name="address" placeholder="请输入准确的超市地址"> <input
									name="status" value="0" style="display:none"/ >
							</div>
						</div>
						<div class="form-group">
							<label class="col-xs-4 control-label">商家介绍</label>
							<div class="col-xs-4">
								<textarea class="col-xs-12" rows="5" id="merchantIntroduce" name="merchantIntroduce"></textarea>
							</div>
						</div>
						
						<div class="anotherDetaile">
							<div class="anotherDetaileButton">
								营业执照图片
								<div class="buttonPic">
									<img src="" style="width:80px;height:80px" id="image2"
										alt="未选择图片" />
								</div>
								<input type="file" name="licenseFile"
									onchange="selectImage2(this)" style="width:200px">
							</div>
							<div class="anotherDetaileButton">
								法人身份证图片
								<div class="buttonPic">
									<img src="" style="width:80px;height:80px" id="image3"
										alt="未选择图片" />
								</div>
								<input type="file" name="identityCardFile"
									onchange="selectImage3(this)" style="width:200px">

							</div>
							<div class="anotherDetaileButton">
								商标专利图片
								<div class="buttonPic">
									<img src="" style="width:80px;height:80px" id="image4"
										alt="未选择图片" />
								</div>
								<input type="file" name="brandFile"
									onchange="selectImage4(this)" style="width:200px">

							</div>
							<div class="anotherDetaileButton">
								QS标示图片
								<div class="buttonPic">
									<img src="" style="width:80px;height:80px" id="image5"
										alt="未选择图片" />
								</div>
								<input type="file" name="qsImgFile"
									onchange="selectImage5(this)" style="width:200px">

							</div>
							<div class="anotherDetaileButton">
								官方授权证书
								<div class="buttonPic">
									<img src="" style="width:80px;height:80px" id="image1"
										alt="未选择图片" />
								</div>
								<input type="file" name="accreditFile"
									onchange="selectImage1(this)" style="width:200px">

							</div>
						</div>
						<div class="form-group">
							<div class="col-xs-4 col-xs-offset-5">
								<button onclick="submitSuper()" class="col-xs-6 btn btn-primary"
									type="button">添加</button>
							</div>
						</div>
					</form>
				</div>
			</div>
		</section>
		<section id="main">
			<div class="scrollbar1-1" id="style1-1">
				<div class="main_div">
					<div class="main_title">
						<span>直营商家管理</span>
					</div>
				</div>
				<form class="form-inline" style="margin-top: 30px;margin-left: 40px">
					<div class="form-group">
						<div class="form-group">
							<label style="margin-left:30px">商家电话：</label> <input type="text"
								id="directPhone" class="form-control" />
						</div>
						<div class="form-group">
							<label style="margin-left:30px">商家名称：</label> <input type="text"
								id="directName" class="form-control" />
						</div>
						<label style="margin-left:30px">商家状态：</label> <select
							class="form-control" id="status">
							<option value="-1">请选择</option>
							<option value="0">正常运营</option>
							<option value="1">已冻结</option>
						</select>
					</div>
					<div class="form-group">
						<button type="button" onclick="selectinfo()"
							class="btn btn-primary">立即查询</button>
					</div>
					<div class="form-group" style="margin-left:300px">
						<button type="button" onclick="addNewAgentcss('#main','#main2')"
							class="btn btn-primary">新增直营商家</button>
					</div>
				</form>
				<div class="force-overflow1-1">
					<table class="table table-condensed table-bordered table-hover"
						id="showTable" style="text-align: center">
						<tr style="background-color: #59c7d2">
							<th style="text-align: center">序号</th>
							<th style="text-align: center">法人</th>
							<th style="text-align: center">商家名称</th>
							<th style="text-align: center">商家电话</th>
							<th style="text-align: center">商家地址</th>
							<th style="text-align: center">商家营业额</th>
							<th style="text-align: center">商家状态</th>
							<th style="text-align: center">备注</th>
							<th style="text-align: center">操作</th>
							<th style="text-align: center">查看直营商家</th>
						</tr>
					</table>
					<div>总营业额：<span id="totalMoney"></span></div>
					<div class="pageChange">
						<span onclick="prePage()">&nbsp;&nbsp;上一页&nbsp;&nbsp;</span> <span
							onclick="nextPage()">&nbsp;&nbsp;下一页&nbsp;&nbsp;</span> <em>
							&nbsp; 第&nbsp;<span id="pageNum">1</span>&nbsp;页&nbsp;&nbsp;
						</em> <em>/&nbsp;&nbsp;共&nbsp;<span id="totalpage"></span>&nbsp;页
						</em> <em>&nbsp;&nbsp;&nbsp;跳到第<input id="searchInput"
							style="width:46px" maxlength="4" type="text">页
						</em>
						<button class="btn btn-primary" onclick="searchPage()">搜索</button>
					</div>
					<input style="display:none" value="7" id="pageCount"
						name="pageCount" />
				</div>
			</div>
		</section>
	</div>
	<script>
		var image = '';
		function selectImage2(file) { //显示图片
			if (!file.files || !file.files[0]) {
				return;
			}
			var reader = new FileReader();
			reader.onload = function(evt) {
				document.getElementById('image2').src = evt.target.result;
				image = evt.target.result;
			};
			reader.readAsDataURL(file.files[0]);
		}
		function selectImage3(file) { //显示图片
			if (!file.files || !file.files[0]) {
				return;
			}
			var reader = new FileReader();
			reader.onload = function(evt) {
				document.getElementById('image3').src = evt.target.result;
				image = evt.target.result;
			};
			reader.readAsDataURL(file.files[0]);
		}
		function selectImage5(file) { //显示图片
			if (!file.files || !file.files[0]) {
				return;
			}
			var reader = new FileReader();
			reader.onload = function(evt) {
				document.getElementById('image5').src = evt.target.result;
				image = evt.target.result;
			};
			reader.readAsDataURL(file.files[0]);
		}
		function selectImage4(file) { //显示图片
			if (!file.files || !file.files[0]) {
				return;
			}
			var reader = new FileReader();
			reader.onload = function(evt) {
				document.getElementById('image4').src = evt.target.result;
				image = evt.target.result;
			};
			reader.readAsDataURL(file.files[0]);
		}
		function selectImage1(file) { //显示图片
			if (!file.files || !file.files[0]) {
				return;
			}
			var reader = new FileReader();
			reader.onload = function(evt) {
				document.getElementById('image1').src = evt.target.result;
				image = evt.target.result;
			};
			reader.readAsDataURL(file.files[0]);
		}
		function submitSuper() {
			$("#passwordOn").val($.md5($("#surePassword").val()))
			//alert($("#passwordOn").val())
			var allInput = $("#uploadForm").find("input");
			var config = true;
			for (var ids = 0; ids < allInput.length; ids++) {
				if (allInput[ids].value) {
				} else {
					config = false;
				}
			}
			if (config) {
				/********************用于判断图片大小以及图片名称是否合法******************/
				var aarr = document.getElementsByTagName("input");
				var barr = [];
				var picreg = /^[A-Za-z0-9\.]{1,100}$/; //图片名称正则
				var flag1 = false; //用于判断图片大小
				var flag2 = false; //用于判断图片名称
				for (var i = 0; i < aarr.length; i++) {
					if (aarr[i].type == "file") {
						barr.push(aarr[i])
					}
				}
				for (var z = 0; z < barr.length; z++) {
					if (barr[z].files[0].size > 200000) { //判断图片大小是否大于200kb
						flag1 = true;
					}
					if (!picreg.test(barr[z].files[0].name)) { //判断图片大小是否大于200kb
						flag2 = true;
					}
				}
				if (flag1) {
					alert("上传图片不得超过200kb每张");
					return;
				}
				if (flag2) {
					alert("图片名称只能由字母与数字组成");
					return;
				}
				/******************用于判断图片大小以及图片名称是否合法****************/
				if ($("#setPassword").val() == $("#surePassword").val()) {
					$.ajax({
						url : urls + "directAction/createDirectInfo",
						type : 'POST',
						cache : false,
						data : new FormData($('#uploadForm')[0]),
						processData : false,
						contentType : false
					}).done(function(res) {
						if (res == true) {
							alert("提交成功")
						//$("#motai").css("display", "none");
						//$("#main").css("display", "block");
						} else if (res == false) {
							alert("提交失败")
						} else if (res == "251") {
							alert("账号或商家名称重复，无法开通商家")
						}
					}).fail(function(res) {
						//console.log(res)
						alert("申请失败，服务器异常，请查看信息是否正确")
					});
				} else {
					alert("两次密码输入不一致")
				}
			} else {
				alert("提交失败，请填写完商家信息")
			}
	
		}
		function addNewAgentcss(m, m2) {
			$(m).css("display", "none");
			$(m2).css("display", "block");
		}
	
	
		$(function() {
			selectinfo()
		})
	
		
	
		function selectinfo() {
			var pageNum = $("#pageNum").html();
			var pageCount = $("#pageCount").val();
			var status = $("#status").find("option:selected").val();
			var directName = $("#directName").val();
			var directPhone = $("#directPhone").val();
			if (status == -1) {
				status = null
			}
			if (directName == "") {
				directName = null
			}
			if (directPhone == "") {
				directPhone = null
			}
			$.post(urls + "directAction/getDirectInfo",
				{
					pageNum : pageNum,
					pageCount : pageCount,
					status : status,
					phone : directPhone,
					directName : directName,
				},
				function(data) {
					//console.log(data)					
					if (data) {
						var totalpage = data.totalpage;
						var orderlist = data.list;
						var table = $("#showTable");
						$("#vipCount").html(data.totalVip)
						$("tr").remove(".addtr");
						$("#totalMoney").text(data.totalMoney)
						for (var i = 0; i < orderlist.length; i++) {
							var button;
							var status,remark="";
							var button3="<button class='btn btn-primary' onclick='watchDirect(\"" + orderlist[i].id + "\")'>查看直营商家</button>"
							if(!orderlist[i].remark){
							   remark="..."
							}else{
							remark=orderlist[i].remark
							}
							
							var button1 = "<button class='btn btn-success' onclick='controlAgent(\"" + orderlist[i].id + "\",0)'>恢复直营商家</button>";
							var button2 = "<button class='btn btn-primary' onclick='controlAgent(\"" + orderlist[i].id + "\",1)'>冻结直营商家</button>";
							if (orderlist[i].status == 0) {
								button = button2;
								status = "正常营业中"
							} else if (orderlist[i].status == 1) {
								button = button1;
								status = "已冻结"
							}
							var append = "<tr class='addtr'><td>" + (i + 1) + "</td>" +
								"<td >" + orderlist[i].userName + "</td>" +
								"<td>" + orderlist[i].directName + "</td>" +
								"<td>" + orderlist[i].phone + "</td>" +
								"<td>" + orderlist[i].address + "</td>" +
								"<td>" + orderlist[i].totalMoney + "</td>" +
								"<td>" + status + "</td>" +
								
								"<td><textarea rows='3' id='" + orderlist[i].id + "' >" + remark + "</textarea></td>" +
								"<td>" + button + "</td>"+
								"<td>" + button3 + "</td></tr>";
							table.append(append);
						}
						$("#totalpage").html(totalpage);
					}
				}
				, "json"
			)
		}
		function controlAgent(id, status) { //是否冻结代理商
			var reason = $("#" + id).val();
			if (confirm("是否继续操作？")) {
				$.post(urls + "directAction/updateDirectInfo",
					{
						id : id,
						status : status,
						remark : reason
					},
					function(res) {
						if (res == true) {
							selectinfo()
						} else if (res = false) {
							alert("操作失败")
						}
					}
				)
			}
		}
		function watchDirect(id){
		 location.href = "${pageContext.request.contextPath}/YMGback/head/watchDirect.jsp?id="+id
		}
	</script>
</body>
</html>